<?php
/**
 * 心灵分享模型
 */
namespace App\Modules;
use DB;
use Illuminate\Database\Eloquent\Model;

class EntMindShare extends Model
{
    /**
     * 关联到模型的数据表
     *
     * @var string
     */
    protected $table = 'MindShare';
    /**
     * 主键
     * @var unknown
     */
    protected $primaryKey = 'MinSgaID';
    /**
     * Eloquent 期望数据表中存在 created_at 和 updated_at 字段。
     *
     * @var unknown
     */
    public $timestamps = false;

    public function get_article_list(){
        $articleList = $this->where('DeleteMark',1)->where('IsShow',1)->get();
        return $articleList;
    }

    /*
     * 获得文章详情
     *
     * */
    public function get_article_info($articleId){
        $articleInfo = $this->where('MinSgaID',$articleId)->first();
        return $articleInfo;
    }


    /*
     * 获取文章的评论信息
     * @param articleId 文章ID
     * @param skip      跳过多少条记录
     * @param pageCount 每页显示的数量
     * @param type      评论类型 即属于什么的评论 STUDY 自学习群 READ 老侯代读
     * */
    public function get_article_comment($articleId,$skip,$pageCount,$type='STUDY'){
        $comment = DB::table('def_comment as a')
            ->leftJoin('memberinfo as b','a.uid','=','b.UserID')
            ->select('a.pid','a.type','a.description','b.YourName','b.FilePath1','a.created_at','a.updated_at')
            ->where('a.pid',$articleId)
            ->where('a.type',$type)
            ->skip($skip)
            ->take($pageCount)
            ->get();
        foreach($comment as $i){
            $i->description = emoji_text_decode($i->description);
            $i->FilePath1   = change_member_head_img($i->FilePath1);
        }
        return $comment;
    }
}